package com.duguo.dynamicmvc.view.dynamic.jsp;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.duguo.dynamicmvc.model.Model;
import com.duguo.dynamicmvc.view.AbstractView;
import com.duguo.dynamicmvc.view.forward.ForwardRequestWrapper;

public class JspView extends AbstractView {
    public JspView(String jspFile) {
        setViewName(jspFile);
    }
    
	public void render(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
		request.setAttribute("model", model);
		
		//FIXME: without the following code, won't work in jetty
		if(request instanceof ForwardRequestWrapper){
			request=((ForwardRequestWrapper)request).getRequest();
		}
		
		request.getRequestDispatcher(getViewName()).forward(request, response);
	}
}
